execute unless items block ~ ~ ~ container.0 *[custom_data~{id:"battery"}] run loot replace block ~ ~ ~ container.0 loot vs:battery
item modify block ~ ~ ~ container.0 {function:set_damage,damage:0}

summon item ~ ~ ~ {Motion:[0.0d,0.6d,0.0d],Item:{id:"apple"},PickupDelay:40s,Tags:[summon]}

data modify entity @n[tag=summon,distance=..3,type=item] Item set from block ~ ~ ~ Items[{Slot:0b}]
playsound minecraft:block.crafter.craft master @a ~ ~ ~ 1.0 1.0

tag @n[tag=summon,distance=..3,type=item] remove summon
item replace block ~ ~ ~ container.0 with air
particle minecraft:wax_off ~ ~ ~ 0.7 0.7 0.7 1 30